// viagui.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "viagui.h"
#include "viawin.h"

using namespace nVIA;

//DWORD g_dwViaTlsIndex;

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
//	LPVOID lpvData; 
//    BOOL fIgnore; 

//	HANDLE h = (HANDLE)GetModuleHandle("viagui.dll");

    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
// 			if ((g_dwViaTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) 
//                 return FALSE; 
// 			break;
		case DLL_THREAD_ATTACH:
// 			lpvData = (LPVOID) LocalAlloc(LPTR, sizeof(PVOID)); 
//             if (lpvData != NULL) 
//                 fIgnore = TlsSetValue(g_dwViaTlsIndex, lpvData); 
			break;
		case DLL_THREAD_DETACH:
// 			lpvData = TlsGetValue(g_dwViaTlsIndex); 
//             if (lpvData != NULL) 
//                 LocalFree((HLOCAL) lpvData); 
			break;
		case DLL_PROCESS_DETACH:
// 			lpvData = TlsGetValue(g_dwViaTlsIndex); 
//             if (lpvData != NULL) 
//                 LocalFree((HLOCAL) lpvData); 
//             TlsFree(g_dwViaTlsIndex); 
			break;
    }

    return TRUE;
}


VIAGUI_API HANDLE	viaCreate(HINSTANCE hInstance, HANDLE hViaCommands)
{
	CGui* via = NULL;
	DWORD id = ::GetCurrentThreadId();
	via = new CGui(hInstance, hViaCommands);
	return via;
}

VIAGUI_API HANDLE	viaCreateDlg(HINSTANCE hInstance, HANDLE hViaCommands)
{
	CGui* via = NULL;

	via = new CGui(hInstance, hViaCommands, true);
	return via;
}

VIAGUI_API int		viaDialog(HANDLE h)
{
	CGui* via = (CGui*) h;
	return via->Dialog();
}

VIAGUI_API void		viaRelease(HANDLE *h)
{
	CGui* via = (CGui*) *h;
	delete via;
	*h = NULL;
}

